﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace BDShop.Framework.Web
{
    public static class SessionHelper
    {
        public static Dictionary<string, object> SessionObjects
        {
            get
            {
                if (HttpContext.Current.Session["SessionObjects"] == null)
                    HttpContext.Current.Session["SessionObjects"] = new Dictionary<string, object>();

                return (Dictionary<string, object>)HttpContext.Current.Session["SessionObjects"];
            }
        }

        public static T GetValueOrDefault<T>(this Dictionary<string, object> DICT, string Key)
        {
            return DICT.ContainsKey(Key) ? (T)Convert.ChangeType(DICT[Key], typeof(T)) : default(T);
        }

        public static void SetValue<T>(this Dictionary<string, object> DICT, string Key,T Value)
        {
            bool flag= DICT.ContainsKey(Key) ? true : false;
            if(flag)
            {
                DICT[Key] = Value;
            }
        }
    }
}
